<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <script type="text/javascript" src="../../inc/ctx.jsp"></script>
        <script type="text/javascript" src="../js/g.js"></script>
        <script type="text/javascript" src="../js/infobase.js"></script>
        <script type="text/javascript" src="http://cdn.uuola.cn/js/formvalid.js" charset="utf-8"></script>
        <link rel="stylesheet" href="../../ked/js/themes/default/default.css" />
        <link rel="stylesheet" href="../../ked/js/plugins/code/prettify.css" />
        <script charset="utf-8" src="../../ked/js/kindeditor-min.js"></script>
        <script charset="utf-8" src="../../ked/js/zh_CN.js"></script>
        <script charset="utf-8" src="../../ked/js/plugins/code/prettify.js"></script>
        <script type="text/javascript" src="http://cdn.uuola.cn/js/iColorPicker.js"></script>
        <script type="text/javascript" src="../js/channeltype.js"></script>
        <link href="../css/com.css" type="text/css" rel="stylesheet"/>
        <style>
            img.s1{width:100px;border:1px #EFEFEF solid;padding:1px;}
            #panel{width:950px;}
            #panel table{width:940px;}
            span.s1{color:#B1B1B1;}
            #submitBtn{width:150px;height:35px;}
        </style>
    </head>
    <body>

        <div id="panel">
            <form id="InfoFrm" name="InfoFrm">
                <table>
                    <tr>
                        <th colspan="3">添加信息</th>
                    </tr>
                    <tr>
                        <td class="r">所属板块：</td>
                        <td>
                            <script>out_select('channeltype');</script>
                        </td>
                        <td>&nbsp;</td>
                    </tr>
                    <tr>
                        <td class="r">信息类别：</td>
                        <td>
                            <span id="ctp_name_path"> 请选择信息类别 </span>
                            <input type="button" value="选择类别" onclick="selectCatelogs();"/> *
                            <input type="hidden" name="cid" id="cid" value="" />
                            <input type="hidden" name="ctp" id="ctp" value=""  valid="required" errmsg="信息分类不能为空!" />
                        </td>
                        <td><div id="err_ctp"></div></td>
                    </tr>
                    <tr>
                        <td width="180" height="27" class="r">信息标题：</td>
                        <td width="49%">
                            <input name="title" type="text" id="title" tabindex="1" size="50" maxlength="60" valid="required" errmsg="信息标题不能为空!" />* 
                        </td>
                        <td width="34%"><div id="err_title"><span class="s1">信息标题.60个字符内.勿使用特殊字符.</span></div></td>
                    </tr>
                    <tr>
                        <td class="r">标题颜色：</td>
                        <td><label for="tcolor"></label>
                            <input type="text" name="tcolor" id="tcolor" tabindex="2" class="iColorPicker">
                            <span class="s1">可选. 用于突出显示标题.</span></td>
                        <td>&nbsp;</td>
                    </tr>
                    <tr>
                        <td class="r">副标题：</td>
                        <td>
                            <input name="subtitle" type="text" id="subtitle"  tabindex="2" size="50"  maxlength="60" />
                            <span class="s1"> </span></td>
                        <td>&nbsp;</td>
                    </tr>
                    <tr>
                        <td class="r">摘要/概要：</td>
                        <td><label for="summary"></label>
                            <textarea name="summary" id="summary" cols="55" rows="4" tabindex="3" valid="limit" min="0" max="200"  errmsg="摘要导读字数范围在200字内!"></textarea></td>
                        <td width="34%"><div id="err_summary"><span class="s1">摘要字数控制在200字内.</span></div></td>
                    </tr>
                    <tr>
                        <td class="r">信息权重：</td>
                        <td>
                            <input name="weight" type="text" id="weight" tabindex="5" value="" maxlength="7"></td>
                        <td><span class="s1">此默认值是依据当前信息表中最大权重+1得出</span></td>
                    </tr>
                    <tr>
                        <td class="r">来源/出处：</td>
                        <td><label for="origin"></label>
                            <input name="origin" type="text" id="origin" tabindex="4" size="50" maxlength="200"></td>
                        <td><span class="s1">格式如：来源名|网址，或者只写来源名</span></td>
                    </tr>
                    <tr>
                        <td class="r">发布时间：</td>
                        <td><input type="text" name="_pubtime" maxlength="19" id="_pubtime" tabindex="5">
                            <input type="button" value="" class="calendar"   onclick="cdpn('_pubtime');"/>
                            <input type="hidden" value="" name="pubtime" id="pubtime"/>
                        </td>
                        <td>&nbsp;</td>
                    </tr>
                    <tr>
                        <td class="r">结束时间：</td>
                        <td>
                            <input type="text" name="_endtime"  maxlength="19"  id="_endtime" tabindex="6">
                            <input type="hidden" value="" name="endtime" id="endtime"/>
                            <input type="button" value="" class="calendar"   onclick="cdpn('_endtime');"/></td>
                        <td>&nbsp;</td>
                    </tr>
                    <tr>
                        <td class="r">作者/发布者：</td>
                        <td><input name="author" type="text" id="author" tabindex="7" maxlength="30" value=""></td>
                        <td>&nbsp;<span class="s1">管理员账号名</span></td>
                    </tr>
                    <tr>
                        <td class="r">信息类型：</td>
                        <td><script>out_infotype();</script></td>
                        <td>&nbsp;</td>
                    </tr>
                    <tr>
                        <td class="r">是否发布：</td>
                        <td>
                            <label>
                                <input name="pubstate" type="radio" id="pubstate_1" value="1" checked>是</label>
                            <label>
                                <input type="radio" name="pubstate" value="0" id="pubstate_0">否</label>
                        </td>
                        <td>&nbsp;</td>
                    </tr>
                    <tr>
                        <td class="r">是否可评：</td>
                        <td><p>
                                <label>
                                    <input type="radio" name="iscmt" value="1" id="iscmt_1">可评</label>

                                <label>
                                    <input name="iscmt" type="radio" id="iscmt_0" value="0" checked>禁止</label>

                            </p></td>
                        <td>&nbsp;</td>
                    </tr>
                    <tr>
                        <td class="r">信息标志：</td>
                        <td><script>out_tflag();</script></td>
                        <td>&nbsp;</td>
                    </tr>
                    <tr>
                        <td class="r">信息主图：</td>
                        <td><label for="pic"></label>
                            <input name="pic" type="text" id="pic" size="50">
                            <input type="button" name="uploadBtn" id="uploadBtn" value="上传图片" tabindex="5" onclick="TxBox.upload('pic', '-ms-ss-', '');">
                        </td>
                        <td>&nbsp;</td>
                    </tr>
                    <tr>
                        <td class="r">跳转地址：</td>
                        <td><label for="gotourl"></label>
                            <input name="gotourl" type="text" id="gotourl" size="50" maxlength="500">
                        </td>
                        <td>&nbsp;<span class="s1">跳转地址以http://开头</span></td>
                    </tr>
                    <tr>
                        <td class="r">视频地址：</td>
                        <td><label for="vodurl"></label>
                            <input name="vodurl" type="text" id="vodurl" size="50" maxlength="100">
                        </td>
                        <td>&nbsp;<span class="s1">地址支持flv,mp4格式,以http://开头</span></td>
                    </tr>
                    <tr>
                        <td height="38"  class="r">信息标签：</td>
                        <td><div id="tagSelect">选择分类信息后自动读取.</div>
                            <input id="tagids" name="tagids" value="" type="hidden" />
                        </td>
                        <td>&nbsp;<input type="button" value="重新载入" onclick="reLoadTags();"/></td>
                    </tr>
                    <tr>
                        <td class="r">信息内容：</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                    </tr>
                    <tr>
                        <td class="r" colspan="3">
                            <textarea name="content" id="content" cols="150" rows="20"></textarea></td>
                    </tr>
                    <tr>
                        <td>&nbsp;</td>
                        <td><input type="hidden" name="channeltype" id="channeltype" value="" /></td>
                        <td>&nbsp;</td>
                    </tr>
                    <tr>
                        <td class="r">&nbsp;</td>
                        <td class="c"><input name="submitBtn" type="button" class="button medium orange" id="submitBtn" tabindex="7" value="添加" onClick="Info.submit();" /></td>
                        <td>&nbsp;</td>
                    </tr>
                    <tr>
                        <td>&nbsp;</td>
                        <td class="c"></td>
                        <td>&nbsp;</td>
                    </tr>
                </table>
            </form>
        </div>



        <script type="text/javascript">
            var frm = ut.e('InfoFrm');
            initValid(frm);

            // 初始化编辑器
            var contentEditor ; 
            KindEditor.ready(function(K) {
                contentEditor = K.create('#content', {
                    uploadJson : KindUpload.UploadUrl,
                    fileManagerJson : KindUpload.fileMgrUrl,
                    allowFileManager : true,
                    afterCreate : function() {
                        var self = this;
                        self.sync();
                    }
                });
                prettyPrint();
            });
            var Info ={
                submit:function(){
                    contentEditor.sync();
                    if(!convertData()){
                        return;
                    }
                    setTagids();
                    if(validator(frm)){
                        $.post('../app/infobase/save.shtm',ut.getFormData('#InfoFrm'),function(x){
                            if($.trim(x)=='ok'){
                                ut.m('添加成功!');
                                ut.reload('?t='+ut.r()+'&channeltype='+$('#channeltype').val());
                            }else{
                                ut.m('添加失败. '+x);
                            }   
                        });
                    }
                }
            };     

            function convertData(){
                var _pt = $('#_pubtime').val();
                var _et = $('#_endtime').val();
                var t1=0 , t2=0;
                if(va.datetime(_pt)){
                    t1 = ut.parseMs(_pt) ;
                }
                if(va.datetime(_et)){
                    t2 =  ut.parseMs(_et) ;
                }
                if(t2>0 && t2<t1){
                    ut.m('结束时间必须大于发布时间.');
                    return false;
                }
                if(t1>0)$('#pubtime').val(t1);
                if(t2>0)$('#endtime').val(t2);
                return true;
            };

            function selectCatelogs(){
                TxBox.winpop(250,350,'类目选择', 'catalogs_select_pop.html?channeltype='+$('#channeltype').val());
            };

            function reloadCatData(cid,ctp){
                $('#cid').val(cid);
                $('#ctp').val(ctp);
                $('#ctp_name_path').text(cid+';'+ctp);
                TxBox.closeWinpop();
                loadTags(cid,ctp);
            };

            function initWeight(){
                $.get('../app/infobase/query_max_weight.shtm?t='+ut.r(),function(x){
                    $('#weight').val((Number($.trim(x))+1));
                });
            };
            
            function loadTags(cid,ctp){
                if(va.isnull(cid)){
                    return;
                }
                var t = '<label><input name="tagid" type="checkbox" value="@tagid"/>@tagname</label>';
                var p={
                    'cid':cid,
                    'pubstate':1,
                    't':ut.r()
                };
                var s =[];
                var jqTagSelect = $('#tagSelect');
                jqTagSelect.html('正在读取标签信息...');
                $.get('../app/tags/query_list.shtm',$.param(p),function(x){
                    if(x.length>0){
                        for(var k in x){
                            s.push(t.replace(/@tagid/g,x[k].tagid).replace(/@tagname/,x[k].tagname)); 
                        }
                        jqTagSelect.html(s.join(''));
                    }else{
                        jqTagSelect.html('没有标签可供选择'); 
                    }
                });
            };
            
            function reLoadTags(){
                loadTags($('#cid').val(),$('#ctp').val());
            };
            
            function setTagids(){
                var tagids = ut.getselv('tagid');
                if(!va.isnull(tagids)){
                    $('#tagids').val(tagids);
                }
            };

            function changeChannelType(){
                $('#ctp_name_path').text('请选择信息类别 ');
                $('#cid').val('');
                $('#ctp').val('');
            };
            
            function initAuthor(){
                $.get('../app/admin/out_name.shtm?'+ut.r(),function(x){
                    if(x.indexOf('Deny')>0){
                       win.close();
                    }else{$('#author').val(x);}
                });
            };
            
            initWeight();
            jQuery(function(){
                $('#channeltype').val('0');
                $('#channeltype').change(function(){
                    changeChannelType();
                    if($('#channeltype').val()!='0'){
                        $('#channeltype').val('0');
                    }
                });
            });
            
            ut.wait(function(){initAuthor();}, 3000);
        </script>
    </body>
</html>